<?php

namespace common\behavior\CommonMessagePushing;


use common\model\EntityModel;
use common\service\BehaviorService;
use common\service\ReviewRequestMessageService;
use common\service\TaskMemberService;
use common\service\UserService;
use Webman\Stomp\Client;

/**
 * 每日登录待办提醒 消息通知
 */
class NotificationTaskSetDailyBehavior
{
    /**
     * @param $params
     * @return void
     */
    public function run($params)
    {
        /***********  预处理开始  ************/
        $params = BehaviorService::getInstance()->dealParam(
            $params,
            [
                'user' => '',
                'count' => '',
            ],
            [
                'user' => [],
                'count' => [],
            ],
            'data',
            ['type' => 'daily_task_notification'],
        );
        /***********  行为判断  ************/
        if ($params === false) {
            return;
        }
        /***********  变量迁移  ************/
        list($user, $count) = $params;
        if (empty($user) || empty($count)) {
            return;
        }
        /***********  预处理结束  ************/

        /***********  原逻辑迁移  ************/
        $templateId = TaskMemberService::getInstance()->getTaskMemberNotifyTemplateId('message_notify_template_config', 'notify_not_started_task_template_id');
        $messageParam = [
            'first' => '每日登录待办提醒',
            'self_todo_number' => $count['to_do'] ?? 0,
            'task_work_order_todo_number' => $count['work_order_to_do'] ?? 0,
            'remark' => '请及时查看'
        ];

        /***********  发送新的队列  ************/
        Client::send('common_message_pushing', build_queue_data_with_xu([
            'message_generated' => [[
                "param" => $messageParam,
                'template_id' => $templateId,
                'content_type' => 'card_message',
                'notice_type' => 'message_task',
                'is_popup' => 1,
                'message_key' => 'not_started_task_statistics_daily',
                'receiver' => $user['union_id']
            ]],
        ]));
        /***********  结束  ************/
    }
}
